var app =getApp();
const skinBehavior = require('../../utils/themeSkin/skinBehavior');

Component({
  /**
	 * 组件的属性列表
	 */ options: {
    addGlobalClass: true
  },
  properties: {
    goodsData: {
      type: null
    },    
    datas: {
      type: null,
    },
    hide_comment:{
      type:null
    }
  },

  behaviors: [skinBehavior],
  lifetimes: {
    attached: function() { // 在组件实例进入页面节点树时执行
     
    }
  },
  observers:{
    'goodsData': function(goodsData) {
      // 修改部分
        this.setData({
          list:goodsData
        });
        this.lookHeight();
        this.get_card_element();
      // 修改部分
    }
  },

  /**
	 * 组件的初始数据
	 */
  data: {
    imgPath: app.globalData.imgPath,
    showLoading: false,
    list:[],
    images:[],
    lookShow:false
  },
  attached() {
    
  },
  ready() {
  },
  /**
	 * 组件的方法列表
	 */
  methods: {
    lookHeight() {
      const query = wx.createSelectorQuery().in(this);
      if(this.data.list.length > 0) {
        this.data.list.map((item,index) => {
          query.select('.desc' + index).boundingClientRect(res=>{
            if(res) {
              this.setData({
                [`list[${index}].lookShow`] :res.height >= 68?true:false
              });
            }
          }).exec()
        })
        
      }
    },
    get_card_element(){
      const query = wx.createSelectorQuery().in(this);
      query.select('.card').boundingClientRect(res=>{
        this.triggerEvent('child_element_height',res&&res.height);
      }).exec()
    },
    handle(e){
      console.log(e,"e===");
      let item = e.currentTarget.dataset.item;
      let index = e.currentTarget.dataset.index;
      app._postNetWork({
        url:app.getNetAddresss('plugin.micro-communities.api.trick.givePraise'),
        data:{tid:item.id},
        success:resdata=>{
          let{result,msg} = resdata.data;
          app.tips(msg);
          if(result){
            
            console.log(this.data.list[index],'====')
            this.data.list.forEach(c_item=>{
              if(c_item.id == item.id){
                c_item.praise_num=1;
              }
              
            })
            this.setData({list:this.data.list});
          }
        }
      })
    },
    jumpDetails(e) {
      let stick_id = e.currentTarget.dataset.stickid;
      wx.navigateTo({
        url: '/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=' + stick_id
      });
    },
    onImageError(e){
      if(e.type=="error"){
        this.data.list.forEach(item => {
          if(item.id == e.currentTarget.dataset.id){
            item.has_many_image[0].url = app.globalData.imgPath + 'img_404.png'
          }
        })
        this.setData({list:this.data.list})
      }
    }
  }
});
